#ifndef __GWCASTFUNC_HPP__
#define __GWCASTFUNC_HPP__

/**
*@file       gwcastfunc.hpp
*@brief      provide type cast
*
*@author     graywind
*@version    1.0.0.0
*@data       2011/12/27
*/

#include "boost/lexical_cast.hpp"
#include "boost/numeric/conversion/cast.hpp"
#include "boost/any.hpp"

///util stuff
namespace gwBedrockUtil
{
        ///use to cast string to default types such as int, short. and back cast is allowed
        template<class Target, class Source>
        class gwLexicalCast;

        ///use to cast default types to another, this could be very safe cast
        template<class Target, class Source>
        class gwNumericCast;

        ///use to cast integer data types to another
        template<class Target, class Source>
        class gwAnyCast;
}

///util stuff
namespace gwBedrockUtil
{
        ///use to cast string to default types such as int, short. and back cast is al
        template<class Target, class Source>
        class gwLexicalCast
        {
        public:
                ///@brief    impl lexical_cast
                ///param[in] Source    original type object
                ///retval    Target    new target type object
                static Target gwCast(const Source& source)
                {
                        return boost::lexical_cast<Target>(source);
                }
        };

        ///use to cast default types to another, this could be very safe cast
        template<class Target, class Source>
        class gwNumericCast
        {
        public:
                ///@brief    impl numeric_cast
                ///param[in] Source    original type object
                ///retval    Target    new target type object
                static Target gwCast(const Source& source)
                {
                        return boost::numeric_cast<Target>(source);
                }
        };

        ///use to cast integer data types to another
        template<class Target, class Source>
        class gwAnyCast
        {
        public:
                ///@brief    impl any_cast
                ///param[in] Source    original type object
                ///retval    Target    new target type object
                static Target gwCast(const Source& source)
                {
                        return boost::any_cast<Target>(boost::any(source));
                }
        };
}


#endif
